var t = require("../../../../@babel/runtime/helpers/toConsumableArray"),
  e = require("../../../../@babel/runtime/helpers/objectSpread2");
Component({
  options: {
    virtualHost: !0
  },
  properties: {
    list: {
      type: Array,
      value: []
    },
    level: {
      type: Number,
      value: 0
    },
    parent: "",
    clickCancel: {
      type: Boolean,
      value: !0
    },
    defaultActive: {
      type: Array,
      value: []
    },
    max: {
      type: Number,
      value: 1
    },
    totalNum: {
      type: Number,
      value: 0
    }
  },
  data: {
    currentActive: 0,
    activeAry: [],
    childActive: {},
    scrollId: null
  },
  externalClasses: ["custom-class"],
  methods: {
    onClickItem: function (t) {
      var e = t.currentTarget.dataset,
        a = e.index,
        i = e.item,
        r = this.data.activeAry,
        c = this.data.parent;
      this.setIndex(a, i), this.triggerEvent("childClick", {
        parent: c,
        activeAry: r
      })
    },
    setIndex: function (t, e) {
      var a = this.data,
        i = a.activeAry,
        r = a.clickCancel,
        c = a.max,
        l = a.totalNum,
        n = i.indexOf(t);
      if (-1 !== n && r) e.children || i.splice(n, 1);
      else {
        if (e.children) return void this.setData({
          currentActive: t
        });
        if (c && !(l < c)) return void $.alert({
          content: "最多选择".concat(c, "个")
        });
        i.push(t)
      }
      this.setData({
        activeAry: i,
        currentActive: t
      })
    },
    childClick: function (t) {
      var e = t.detail,
        a = e.activeAry,
        i = e.parent,
        r = this.data.childActive;
      r[i] = a, this.setData({
        childActive: r
      }), this.triggerEvent("childClick", {
        parent: i,
        activeAry: a
      })
    },
    setDataValue: function (t) {
      this.setData(e({}, t))
    }
  },
  lifetimes: {
    ready: function () {
      var e = this.data.defaultActive,
        a = e.length ? Math.min.apply(Math, t(e)) : 0;
      this.setData({
        activeAry: e,
        currentActive: e[0],
        scrollId: "scrollId".concat(a)
      })
    }
  }
});